home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / mkmf / mkmf.kernel < prev    next >
Encoding:
Text File  |  1992-10-22  |  3.7 KB  |  132 lines

  1. #!/sprite/cmds/csh -f
  2. #
  3. # A script to generate (or regenerate) a kernel module Makefile
  4. # from a prototype Makefile.  If ./Makefile.proto exists, use it, else
  5. # use a common prototype.
  6. #
  7. # This script is invoked from mkmf.
  8. #
  9. # Parameters passed in from mkmf as environment variables:
  10. #    DOMACHINES    names of machines we are supposed to run mkmf on
  11. #    MKMFDIR        directory containing prototype makefiles
  12. #    MKMFFLAGS    arguments to all mkmfs run recursively
  13. #    MACHINES    list of machine names (e.g. "sun2 sun3"), for
  14. #            which there are machine-specific subdirectories
  15. #            (sun2.md, sun3.md) to hold the object files and
  16. #            any machine-specific source files to use when
  17. #            compiling for that machine
  18. #    MAKEFILE    name of makefile to create
  19. #    SUBTYPE        information about the type makefile
  20. #            
  21. # $Header: /sprite/lib/mkmf/RCS/mkmf.kernel,v 1.23 92/06/10 13:04:40 jhh Exp $ (SPRITE) Berkeley
  22. #
  23.  
  24. onintr cleanup
  25.  
  26.  
  27. #
  28. # Argument processing.  (Generalized form, even though just one flag so far.)
  29. #
  30. set type=$0
  31. set type=$type:e
  32.  
  33. while ($#argv >= 1)
  34.     if ("$1" == '-x') then
  35.     set echo
  36.     endif
  37.     shift
  38. end
  39. set subtype=$SUBTYPE
  40. set name=$cwd:t
  41. set pref='[a-z_A-Z]'
  42. #
  43. # We no longer support the sun3 and the ds3100 so don't run mkmf for those
  44. # machine types. 
  45. #
  46. set machines=(`echo $MACHINES | sed -e "s/sun3//g" -e "s/ds3100//g"`)
  47. set domachines=(`echo $DOMACHINES | sed -e "s/sun3//g" -e "s/ds3100//g"`)
  48. set makefile=$MAKEFILE
  49. set distdir=($DISTDIR)
  50.  
  51. if (-e $makefile.proto) then
  52.     set proto=$makefile.proto
  53. else
  54.     set proto="${MKMFDIR}/Makefile.$type"
  55. endif
  56.  
  57. echo "Generating $makefile for module $name from $proto"
  58.  
  59.  
  60. set nonomatch
  61. set hdrs =( ${name}*.h )
  62. if ("$hdrs" == "${name}*.h") set hdrs=()
  63. set pubHdrs=(`echo $hdrs | sed -e "s/[^ ]*Int.h//g"`)
  64. set allSrcs =( ${pref}*.[cylsp] )
  65. #
  66. # Check to see if there were any sources.  The first check (size == 1)
  67. # is only necessary because the second check will cause an error if
  68. # allSrcs contains more than 1024 bytes.
  69. #
  70. if ($#allSrcs == 1) then
  71.     if ("$allSrcs" == "${pref}*.[cylsp]") set allSrcs=()
  72. endif
  73. set mdsrcs =( *.md/${pref}*.[cylsp] )
  74. if ($#mdsrcs == 1) then
  75.     if ("$mdsrcs" == "*.md/${pref}*.[cylsp]") set mdsrcs=()
  76. endif
  77. set allSrcs=($allSrcs $mdsrcs)
  78. set mdhdrs =( *.md/${pref}*.h )
  79. if ($#mdhdrs == 1) then
  80.     if ("$mdhdrs" == "*.md/${pref}*.h") set mdhdrs=()
  81. endif
  82. set allHdrs =($hdrs $mdhdrs)
  83. unset nonomatch
  84.  
  85. #
  86. # Use sed to substitute various interesting things into the prototype
  87. # makefile. The code below is a bit tricky because some of the variables
  88. # being substituted in can be very long:  if the substitution is passed
  89. # to sed with "-e", the entire variable must fit in a single shell argument,
  90. # with a limit of 1024 characters.  By generating a separate script file
  91. # for the very long variables, the variables get passed through (to the
  92. # script file) as many arguments, which gets around the length problem.
  93. #
  94.  
  95. rm -f mkmf.tmp.sed
  96. echo s,"@(ALLSRCS)",$allSrcs,g > mkmf.tmp.sed
  97. echo s,"@(ALLHDRS)",$allHdrs,g >> mkmf.tmp.sed
  98. cat $proto | sed -f mkmf.tmp.sed \
  99.     -e "s,@(DATE),`date`,g" \
  100.     -e "s,@(MACHINES),$machines,g" \
  101.     -e "s,@(MAKEFILE),$makefile,g" \
  102.     -e "s,@(NAME),$name,g" \
  103.     -e "s,@(PUBHDRS),$pubHdrs,g" \
  104.     -e "s,@(TEMPLATE),$proto,g" \
  105.     -e "s, $name.ln,,g" \
  106.     -e "s,@(DISTDIR),$distdir,g" \
  107.     -e "s,@(TYPE),$subtype,g" \
  108.     > $makefile
  109. rm -f mkmf.tmp.sed
  110.  
  111. setenv PARENTDIR $cwd
  112.  
  113. if ($#domachines != 1) then
  114.     cat << EOF > "#mkmf.$$"
  115. all :: $domachines
  116. $domachines ::
  117.     @ cd \$@.md
  118.     @ mkmf \$MKMFFLAGS -f md.mk 
  119.     @ mv md.mk md.mk.tmp 
  120.     @ sed -e "s| \$@\.md/$name\.o||g" md.mk.tmp > md.mk 
  121.     @ rm -f md.mk.tmp
  122. EOF
  123.     pmake -f "#mkmf.$$"
  124. else
  125.     foreach i ($domachines)
  126.         (cd $i.md; mkmf $MKMFFLAGS -f md.mk; mv md.mk md.mk.tmp; sed -e "s| $i\.md/$name\.o||g" md.mk.tmp > md.mk; rm -f md.mk.tmp)
  127.     end
  128. endif
  129.  
  130. cleanup:
  131.     rm -f "#mkmf.$$" mkmf.tmp.sed
  132.